package com.code.day22;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Properties;

public class Demo04Reflect {
    public static void main(String[] args) throws Exception {
        //1.创建Properties集合对象
        Properties properties = new Properties();
        //2.读取配置文件
        InputStream resourceAsStream = Demo04Reflect.class.getClassLoader().getResourceAsStream("reflect.properties");;
        //3.将流中的数据加载到properties集合中
        properties.load(resourceAsStream);
        //4.根据解析出来的className创建Class对象
        String className = properties.getProperty("className");
        Class<?> aClass = Class.forName(className);
        //5.创建一个对象
        Object o = aClass.newInstance();
        //6.根据解析出来的methodName获取方法
        String methodName = properties.getProperty("methodName");
        Method method = aClass.getMethod(methodName);
        //7.执行方法 等价于 o.study();
        method.invoke(o);
        //8.关流
        resourceAsStream.close();
    }
}
